<!DOCTYPE html>
<html>

<head>
    {include file="Public/header"}

    <link rel="stylesheet" href="__STATIC__/layout/css/zTreeStyle.css" type="text/css">
    <style>
        .col-md-4 label {
            width: 120px;
            margin-bottom: 0;
            display: inline-block;
            line-height: 40px;
            border-right: 1px solid #ccc;
            text-align: right;
            padding-right: 10px
        }
        .col-md-4 input {
            margin-left: 15px
        }
        select {
            width: 150px;
            height: 22px;
        }
        input[type="text"] {
            height: 22px;
            width: 150px
        }
        table {
            border: 1px solid #ccc;
        }
        table {
            border-right: 1px solid #ccc;
            border-bottom: 1px solid #ccc
        }
        table th {
            text-align: center;
            vertical-align: middle;
        }
        table td {
            border-left: 1px solid #ccc;
            border-top: 1px solid #ccc;
            text-align: center;
            vertical-align: middle;
        }
        table tbody {
            background: #fff
        }

        h3 {
            font-weight: normal;
            text-align: left;
            line-height: 24px;
            font-size: 20px;
            padding-left: 1%;
            width: 99%;
            margin-bottom: 30px;
            background: #a8c8e8
        }
        .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form form {
            width: 100%;
        }
        .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form form div label {
            display: inline-block;
            width: 130px;
            text-align: right;
            margin-left: 24%;
        }
        .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form form div:nth-of-type(1) input {
            margin-right: 28px;
        }
        .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form form div button:hover {
            background: #5bc0de
        }

        /*区省市样式*/
        .alert_zoneTree_content_tree {
            background: #f4f4f5;
            margin: 0;
            padding: 5px;
            /*border: 4px solid #ccc*/
        }

        .alert_zoneTree_content_tree #zoneTree {
            overflow-y: scroll;
        }

        .alert_zoneTree_content_tree #zoneTree #treeDemo2 {
            height: 305px
        }
    </style>
</head>

<body class="gray-bg" style="color:#333;padding:3px;">

<div class="alert_zoneTree_content_tree">
    <div class="alert_addNewZone_form_tree" id="zoneTree">
        <ul id="treeDemo2" class="ztree"></ul>
        <div class="quedingbtn" style="margin:0 auto;width:100%;text-align: center;">
                <button id="queding">确定</button>
        </div>
    </div>
</div>
<input type="hidden" id="data" value="[]">
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<!-- <script src="js/plugins/layer/layer.min.js"></script> -->

<!-- 自定义js -->
<script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>

<!-- ztree -->
<script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.excheck.js"></script>
<!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script> -->
<script>

    var setting2 = {
        check: {
            enable: true,
//            chkStyle: "radio",
            radioType: "all"
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: emOnCheck
        }
    };

    function abcd(id,name) {
        var data = $('#data').val()
        data = JSON.parse(data)
        data.push({
            'id':id,
            'title':name
        })
        $('#data').val(JSON.stringify(data))
    }
    function abcd2(id) {
        var data = $('#data').val()
        data = JSON.parse(data)
        for(var i=0;i<data.length;i++){
            if(data[i].id==id){
                data.splice(i,1);
            }
        }
        $('#data').val(JSON.stringify(data))
    }
    //递归查找所有叶子节点的id
    function getAllChildrenNodes(treeNode){
        if (treeNode.isParent) {
            var childrenNodes = treeNode.children;
            if (childrenNodes) {
                for (var i = 0; i < childrenNodes.length; i++) {
                     getAllChildrenNodes(childrenNodes[i]);
                }
            }
        }else{
            if(treeNode.level==2) //只有层级等于4才是产品
                abcd(treeNode.id,treeNode.name)  
        }
        //return result;
    }
     function getAllChildrenNodes2(treeNode){
        if (treeNode.isParent) {
            var childrenNodes = treeNode.children;
            if (childrenNodes) {
                for (var i = 0; i < childrenNodes.length; i++) {
                     getAllChildrenNodes2(childrenNodes[i]);
                }
            }
        }else{
            if(treeNode.level==2) //只有层级等于4才是产品
                abcd2(treeNode.id)  
        }
        //return result;
    }
    //树选择
    function emOnCheck(event, treeId, treeNode) {
        if (treeNode.checked == true) {

            getAllChildrenNodes(treeNode)
           
        } else {
            getAllChildrenNodes2(treeNode)
           
        }
    };
     $('#queding').on('click',function () {

        var sqqy=parent.$("#sqqy");

        var sqqystr=parent.$("#sqqystr");
        //alert(sqqystr.html());
        $.post("{:url('getfullarea')}",{txt:$('#data').val()},function(re){
            //alert(re);
            var data=JSON.parse(re);
            sqqy.val(data["id"]);
            sqqystr.val(data["txt"]);
            parent.layer.close(parent.layer.getFrameIndex(window.name))
        })

     })
    $(document).ready(function () {
        $.post('{:url("sqqyTree")}',
            {},
            function (data) {
                $.fn.zTree.init($("#treeDemo2"), setting2, data);
            },'json')

    });
</script>
<script>

</script>
</body>

</html>
